---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table_a1.log
  log type:  text
 opened on:  17 Aug 2020, 13:40:08

. 
. use "$path/nc_dataset.dta" if new_reg == 0, clear

. 
. drop black white hispanic othernw new_reg noid_p_2016 dem rep

. 
. // drop 2018 
. drop if inlist(election, 11, 12)
(13,254,638 observations deleted)

. 
. sort id election

. 
. replace voted = 0 if voted == .
(0 real changes made)

. 
. // replace voted with NA if under 18 / ineligible in that election year 
. drop if birth_year > 1998 & birth_year < 9999
(70 observations deleted)

. replace voted = . if (birth_year > 1990 & birth_year < 9999) & (election == 1 | election == 2) // 2008
(1,102,090 real changes made, 1,102,090 to missing)

. replace voted = . if (birth_year > 1992 & birth_year < 9999) & (election == 3 | election == 4) // 2010
(680,176 real changes made, 680,176 to missing)

. replace voted = . if (birth_year > 1994 & birth_year < 9999) & (election == 5 | election == 6) // 2012
(269,954 real changes made, 269,954 to missing)

. replace voted = . if (birth_year > 1996 & birth_year < 9999) & (election == 7 | election == 8) // 2014
(314 real changes made, 314 to missing)

. 
. ** create string encoding of possible pre-treatment outcome paths
. tostring voted, generate(outcome_path)
outcome_path generated as str1

. 
. // get pre-treatment path thorugh 2012 general for placebo test for 2014 primary
. by id: gen outcome_path_pretreat = outcome_path[1] + outcome_path[2] + ///
>                                                                 outcome_path[3] + outcome_path[4] + ///
>                                                                 outcome_path[5] + outcome_path[6] 

. 
. 
. // keep primary only
. keep if mod(election,2) == 1
(33,136,560 observations deleted)

. 
. replace voted = 0 if voted == .
(1,026,267 real changes made)

. 
. gen count = 1

. 
. // generate lead
. gen treat_lead = treat[_n+1] if id == id[_n+1]
(6,627,312 missing values generated)

. replace treat_lead = 0 if treat_lead == .
(6,627,312 real changes made)

. 
. // construct age bins, give young voters who are ineligible for some election their own age bin
. gen age_bin = 11 if (birth_year > 1990 & birth_year < 9999)
(30,381,335 missing values generated)

. replace age_bin = 12 if (birth_year > 1992 & birth_year < 9999)
(1,700,440 real changes made)

. replace age_bin = 13 if (birth_year > 1994 & birth_year < 9999)
(674,885 real changes made)

. replace age_bin = 14 if (birth_year > 1996 & birth_year < 9999)
(785 real changes made)

. // give those who are eligible over the whole period their own age decile
. xtile age_decile = birth_year if (birth_year <= 1990), nq(10)

. replace age_bin = age_decile if (birth_year <= 1990)
(30,334,280 real changes made)

. drop age_decile

. 
. compress
  variable count was float now byte
  variable treat_lead was float now byte
  variable age_bin was float now byte
  (298,229,040 bytes saved)

. 
. sort id election

. 
. 
. * vanilla diff in diff
. reghdfe voted treat treat_lead, a(id election) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,136,560
Absorbing 2 HDFE groups                           F(   2,6627311) =    8090.24
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5364
                                                  Adj R-squared   =     0.4205
                                                  Within R-sq.    =     0.0004
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3269

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0712564   .0007434   -95.86   0.000    -.0727134   -.0697994
  treat_lead |   .0264736   .0005644    46.91   0.000     .0253674    .0275798
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
    election |            4               5              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b1 = _b[treat]

. local se1 = _se[treat]

. local b1_2 = _b[treat_lead]

. local se1_2 = _se[treat_lead]

. local n1 = e(N)

. local nclust1 = e(N_clust)

. 
. * race by year
. reghdfe voted treat treat_lead, a(id race_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,136,560
Absorbing 2 HDFE groups                           F(   2,6627311) =    6759.31
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5414
                                                  Adj R-squared   =     0.4267
                                                  Within R-sq.    =     0.0003
Number of clusters (id)      =  6,627,312         Root MSE        =     0.3251

                             (Std. Err. adjusted for 6,627,312 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0667111   .0007501   -88.94   0.000    -.0681811    -.065241
  treat_lead |   .0233205   .0005686    41.01   0.000      .022206     .024435
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6627312        6627312 *   | 
race_by_year |           24              25              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b2 = _b[treat]

. local se2 = _se[treat]

. local b2_2 = _b[treat_lead]

. local se2_2 = _se[treat_lead]

. local n2 = e(N)

. local nclust2 = e(N_clust)

. 
. * age by year 
. reghdfe voted treat treat_lead, a(id age_by_year) cluster(id)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,089,505
Absorbing 2 HDFE groups                           F(   2,6617900) =    4043.20
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5433
                                                  Adj R-squared   =     0.4291
                                                  Within R-sq.    =     0.0002
Number of clusters (id)      =  6,617,901         Root MSE        =     0.3245

                             (Std. Err. adjusted for 6,617,901 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0483346   .0007538   -64.12   0.000    -.0498121   -.0468572
  treat_lead |   .0225755   .0005685    39.71   0.000     .0214612    .0236899
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          id |            0         6617901        6617901 *   | 
 age_by_year |          444             445              1     | 
---------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b3 = _b[treat]

. local se3 = _se[treat]

. local b3_2 = _b[treat_lead]

. local se3_2 = _se[treat_lead]

. local n3 = e(N)

. local nclust3 = e(N_clust)

. 
. * age by race by year
. reghdfe voted treat treat_lead, a(id race_by_age_by_year) cluster(id)
(dropped 20 singleton observations)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   = 33,089,485
Absorbing 2 HDFE groups                           F(   2,6617896) =    3310.03
Statistics robust to heteroskedasticity           Prob > F        =     0.0000
                                                  R-squared       =     0.5490
                                                  Adj R-squared   =     0.4363
                                                  Within R-sq.    =     0.0002
Number of clusters (id)      =  6,617,897         Root MSE        =     0.3224

                             (Std. Err. adjusted for 6,617,897 clusters in id)
------------------------------------------------------------------------------
             |               Robust
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
       treat |  -.0421138   .0007606   -55.37   0.000    -.0436046   -.0406229
  treat_lead |   .0225271   .0005737    39.27   0.000     .0214027    .0236516
------------------------------------------------------------------------------

Absorbed degrees of freedom:
----------------------------------------------------------------------+
        Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
--------------------+-------------------------------------------------|
                 id |            0         6617897        6617897 *   | 
race_by_age_by_year |         2179            2180              1     | 
----------------------------------------------------------------------+
* = fixed effect nested within cluster; treated as redundant for DoF computation

. local b4 = _b[treat]

. local se4 = _se[treat]

. local b4_2 = _b[treat_lead]

. local se4_2 = _se[treat_lead]

. local n4 = e(N)

. local nclust4 = e(N_clust)

. 
. 
. // drop 2016 primary
. drop if election == 9 
(6,627,312 observations deleted)

. 
. preserve 

. 
. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election)

. 
. *** get N by path by summing together n treated and n control
. by outcome_path: gen tot_tmp = count[5] if _n==5
(595 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path)

. by outcome_path: replace tot_tmp = count[1] if _n == 1
(85 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  4
Number of records is  680

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 8 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/8)

. gen tot_treat2 = round(tot_treat/8)

. egen op = group(outcome_path)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 32 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,784
Absorbing 2 HDFE groups                           F(   1, 218699) =      14.55
                                                  Prob > F        =     0.0001
                                                  R-squared       =     0.6494
                                                  Adj R-squared   =     0.6492
                                                  Within R-sq.    =     0.0001
                                                  Root MSE        =     0.1925

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0031406   .0008233    -3.81   0.000    -.0047542    -.001527
-------------+----------------------------------------------------------------
    Absorbed |     F(83, 218699) =   4879.917   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |           81              81              0     | 
    election |            3               4              1     | 
---------------------------------------------------------------+

. local b5 = _b[no_dmv_match]

. local se5 = _se[no_dmv_match]

. local n5 = N

. local nclust5 = N_voters

. 
. restore 

. preserve 

. 
. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string no_dmv_match election

. by outcome_path race_string: gen tot_tmp = count[5] if _n==5
(2,772 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string)

. by outcome_path race_string: replace tot_tmp = count[1] if _n == 1
(420 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  4
Number of records is  3136

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 8 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/8)

. gen tot_treat2 = round(tot_treat/8)

. egen op = group(outcome_path race_string)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 744 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    218,848
Absorbing 2 HDFE groups                           F(   1, 218545) =      10.93
                                                  Prob > F        =     0.0009
                                                  R-squared       =     0.6497
                                                  Adj R-squared   =     0.6492
                                                  Within R-sq.    =     0.0001
                                                  Root MSE        =     0.1927

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0027236   .0008237    -3.31   0.001    -.0043381   -.0011091
-------------+----------------------------------------------------------------
    Absorbed |    F(301, 218545) =   1346.424   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |          299             299              0     | 
    election |            3               4              1     | 
---------------------------------------------------------------+

. local b6 = _b[no_dmv_match]

. local se6 = _se[no_dmv_match]

. local n6 = N

. local nclust6 = N_voters

. 
. restore

. 
. collapse (sum) count (mean) voted, by(outcome_path_pretreat no_dmv_match election race_string age_bin)

. 
. // drop if age is missing
. drop if age_bin == .
(752 observations deleted)

. 
. *** get N by path by summing together n treated and n control
. sort outcome_path race_string age_bin no_dmv_match election

. by outcome_path race_string age_bin: gen tot_tmp = count[5] if _n==5
(18,313 missing values generated)

. egen tot_treat = sum(tot_tmp), by(outcome_path race_string age_bin)

. by outcome_path race_string age_bin: replace tot_tmp = count[1] if _n == 1
(3,061 real changes made)

. egen tot = sum(tot_tmp), by(outcome_path race_string age_bin)

. // N_voters is the number of voters who enter into the regression
. egen N_voters = sum(tot_tmp)

. // get number of elections
. unique election
Number of unique values of election is  4
Number of records is  20336

. // N is number of voters * number of elections
. gen long N = N_voters * r(unique)

. drop tot_tmp

. gen tot_control = tot - tot_treat

. 
. *** get weights for fw based on total n per stratum
. *** each stratum has 8 obs
. *** fw requires integers so need to round
. gen tot2 = round(tot/8)

. gen tot_treat2 = round(tot_treat/8)

. egen op = group(outcome_path race_string age_bin)

. 
. reghdfe voted no_dmv_match [fw=tot_treat2], a(op election)
weight tot_treat2 can only contain strictly positive integers, but 10512 zero values were found (will be dropped)
(converged in 3 iterations)

HDFE Linear regression                            Number of obs   =    211,936
Absorbing 2 HDFE groups                           F(   1, 210704) =      20.61
                                                  Prob > F        =     0.0000
                                                  R-squared       =     0.6515
                                                  Adj R-squared   =     0.6495
                                                  Within R-sq.    =     0.0001
                                                  Root MSE        =     0.1912

------------------------------------------------------------------------------
       voted |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
no_dmv_match |  -.0037707   .0008305    -4.54   0.000    -.0053986   -.0021429
-------------+----------------------------------------------------------------
    Absorbed |   F(1230, 210704) =    320.210   0.000             (Joint test)
------------------------------------------------------------------------------

Absorbed degrees of freedom:
---------------------------------------------------------------+
 Absorbed FE |  Num. Coefs.  =   Categories  -   Redundant     | 
-------------+-------------------------------------------------|
          op |         1228            1228              0     | 
    election |            3               4              1     | 
---------------------------------------------------------------+

. local b7 = _b[no_dmv_match]

. local se7 = _se[no_dmv_match]

. local n7 = N

. local nclust7 = N_voters

. 
. log close
      name:  <unnamed>
       log:  /Users/jesse/Dropbox/voter_id/Replication/table_a1.log
  log type:  text
 closed on:  17 Aug 2020, 14:02:35
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
